package ij.hkust;

import ij.IJ;
import ij.process.ImageProcessor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * some constant value
 * @author liuquan
 *
 */
public class Constants {

	public static int LASER_MAX_POWER = 4500;
	public static int DELAY_EACH_PERIOD = 10;
	
	public static Map<String,String> laserFH = new HashMap<String,String>();
	public static Map<String,String> laserID = new HashMap<String,String>();
	
	public static String fileSavePath = "D:\\test\\";//here is the dir we save our file.
	public static Map<Integer,Integer> channelCount = new HashMap<Integer,Integer>();//the count for each channel's image
	
	public static int curChannel = 0;
	
	//the raw images, every time we start a new capture, we will clear this list
//	public static List<ImageProcessor> rawImages = new ArrayList<ImageProcessor>();
	public static List<Object> rawImages = new ArrayList<Object>();
	public static List<Integer> imgChannel = new ArrayList<Integer>();//this is used to determin the channel of the images in rawImages list
	public static int curRawImgChannel = 0;
	public static int rawIndex = 0;
	//the reconstructed images.
	public static List<Object> recImages = new ArrayList<Object>();
	public static List<Integer> recChannel = new ArrayList<Integer>();
	public static int recIndex = 0;
	//the current image that we are processing
	public static int index = 0;
	//the size of the images we take
	public static int imgWidth = 0;
	public static int imgHeight = 0;
	
	
	//for daostorm only
	public static boolean isCanStart = false;
	
	public static int totalImageCount = 0;
	
	static{
		laserFH.put("405", "153.7560");
		laserFH.put("459", "123.1750");
		laserFH.put("488", "113.7680");
		laserFH.put("532", "99.2574");
		laserFH.put("561", "93.6800");
		laserFH.put("656", "77.3082");
		
		laserID.put("405", "0");
		laserID.put("459", "1");
		laserID.put("488", "2");
		laserID.put("532", "3");
		laserID.put("561", "4");
		laserID.put("656", "5");
	}
	/**
	 * get the channel's dir to save files
	 * @param channel
	 * @return
	 */
	public static String getFilePath(int channel){
//		IJ.showMessage("" + channel);
		if(channel < 0){
			return null;
		}else{
			curChannel = channel;
			return fileSavePath + channel + "\\";
		}
	}
	
	public static int getImageCount (int channel){
		if(channelCount.get(channel) == null){
			channelCount.put(channel, 0);
		}
		int tmp = channelCount.get(channel);
		channelCount.put(channel, tmp + 1);
		 return channelCount.get(channel);
	}
	/**
	 * add raw images to the memery, we only save 100 images in memery
	 * @param img
	 */
	public static void addRawImage(Object img,int channel){
		if(channelCount.get(channel) == null){
			channelCount.put(channel, 0);
		}
		totalImageCount++;
		synchronized(rawImages){
			if(img != null){
				rawImages.add(img);
				imgChannel.add(channel);
	//			rawIndex ++;
				while(rawImages.size() > 100){
					rawImages.remove(0);
					imgChannel.remove(0);
					rawIndex--;
				}
			}
		}
	}
	/**
	 * get a image from the rawImage list
	 * @return
	 */
	public static Object getRawImage(){
		synchronized(rawImages){//give a synchronized ,because the get and add are not in the same thread.
			if(rawIndex >= 0 && rawIndex < rawImages.size() - 1){
				rawIndex ++;
				curRawImgChannel = imgChannel.get(rawIndex);
				return rawImages.get(rawIndex);
			}
		}
		return null;
	}
	public static int getImgChannel(){
//		if(rawIndex >= 0 && rawIndex < imgChannel.size() - 1){
////			rawIndex ++;
//			return imgChannel.get(rawIndex);
//		}
		return curRawImgChannel;
	}
	
	/**
	 * add a reconstruted image to the list--not used
	 * @param img
	 * @param channel
	 */
	public static void addRecImage(Object img,int channel){
		if(img != null){
		
			recImages.add(img);
			recChannel.add(channel);
			while(recImages.size() > 100){
				recImages.remove(0);
				recChannel.remove(0);
			}
		}
	}
	
	/**
	 * here we reset the image's count and clear all the old data
	 */
	public static void resetImage(){
		channelCount.clear();
		rawImages.clear();
		recImages.clear();
	}
}
